package com.andy.note.boot.controller.doctor;

import cn.hutool.core.lang.Console;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.sax.handler.RowHandler;
import com.andy.note.boot.model.entity.doctor.DoctorAnalyse;
import com.andy.note.boot.service.doctor.IDoctorAnalyseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author andy
 * @since 2021-07-30
 */
@RestController
@RequestMapping("/doctor")
@Slf4j
public class DoctorAnalyseController {
    
    @Autowired
    private IDoctorAnalyseService doctorAnalyseServiceImpl;

    @RequestMapping("save")
    public String save() {
        ExcelReader reader = ExcelUtil.getReader("e:/desktop/doctorData.xlsx");
        List<DoctorAnalyse> all = reader.readAll(DoctorAnalyse.class);
        
        List<DoctorAnalyse> list = all.stream().filter(x -> x.getBooking() != null).collect(Collectors.toList());
        
        doctorAnalyseServiceImpl.saveBatch(list);
        
        return list.toString();
    }
    
    
    private RowHandler createRowHandler() {
        return new RowHandler() {
            @Override
            public void handle(int sheetIndex, long rowIndex, List<Object> rowlist) {
                Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist);
            }
        };
    }

    
    public static void main(String[] args) {
        
        
    }
}

